#include "lan2calcalendar.h"
#include "lan2caldelegate.h"
#include "lan2calmodel.h"

#include <QAction>
#include <QToolButton>
#include <QDebug>
#include <QStandardItemModel>
#include <QHeaderView>
LAN2STA
Lan2CalCalendar::Lan2CalCalendar(QWidget *parent) : QWidget(parent)
{
    method_initLayout();
    method_addHeadWidget();
}

void Lan2CalCalendar::method_initLayout()
{
    mvbox=new QVBoxLayout();
    this->setLayout(mvbox);

    hbox_head=new QHBoxLayout();
    mvbox->addLayout(hbox_head);

    method_initView();
    mvbox->addWidget(mview);



}

void Lan2CalCalendar::method_addHeadWidget()
{
    QToolButton* mtb_leftArrow=new QToolButton(this);
    mtb_leftArrow->setToolButtonStyle(Qt::ToolButtonIconOnly);
    mtb_leftArrow->setIcon(this->style()->standardIcon(QStyle::SP_MediaSeekBackward));
    connect(mtb_leftArrow,SIGNAL(clicked(bool)),this,SLOT(slot_leftarrowClick()));
    hbox_head->addWidget(mtb_leftArrow);

    QToolButton* mtb_leftArrow2=new QToolButton(this);
    mtb_leftArrow2->setToolButtonStyle(Qt::ToolButtonIconOnly);
    mtb_leftArrow2->setIcon(this->style()->standardIcon(QStyle::SP_ArrowLeft));
    connect(mtb_leftArrow2,SIGNAL(clicked(bool)),this,SLOT(slot_leftarrowClick()));
    hbox_head->addWidget(mtb_leftArrow2);

    QComboBox* cbox_MM=new QComboBox(this);
    cbox_MM->addItem("9月");
    hbox_head->addWidget(cbox_MM);

    QComboBox* cbox_YYYY=new QComboBox(this);
    cbox_YYYY->addItem("2022年");
    hbox_head->addWidget(cbox_YYYY);


    QToolButton* mtb_rightArrow2=new QToolButton(this);
    mtb_rightArrow2->setToolButtonStyle(Qt::ToolButtonIconOnly);
    mtb_rightArrow2->setIcon(this->style()->standardIcon(QStyle::SP_ArrowRight));
    connect(mtb_rightArrow2,SIGNAL(clicked(bool)),this,SLOT(slot_rightarrowClick()));
    hbox_head->addWidget(mtb_rightArrow2);


    QToolButton* mtb_rightArrow=new QToolButton(this);
    mtb_rightArrow->setToolButtonStyle(Qt::ToolButtonIconOnly);
    mtb_rightArrow->setIcon(this->style()->standardIcon(QStyle::SP_MediaSeekForward));
    connect(mtb_rightArrow,SIGNAL(clicked(bool)),this,SLOT(slot_rightarrowClick()));
    hbox_head->addWidget(mtb_rightArrow);

    hbox_head->addStretch();



}

void Lan2CalCalendar::method_initView()
{
 mview=new QTableView(this);
 //画表头网络线
mview->horizontalHeader()->setStyleSheet("QHeaderView::section{background:#ffffff;border-top:0px;"
                                         "border-right:0px solid #e5e5e5;"
                                         "border-bottom:0px solid #e5e5e5;"
                                         "border-left:0px;}");
//mview->setStyleSheet("QTableView{background:#c3c3c3;}");
 Lan2CalModel* model=new Lan2CalModel(this);
 model->setColumnCount(7);
 model->setRowCount(6);
 QStringList list_headlabels=QStringList()<<QStringLiteral("一")<<QStringLiteral("二")
                                         <<QStringLiteral("三")<<QStringLiteral("四")
                                        <<QStringLiteral("五")<<QStringLiteral("六")
                                       <<QStringLiteral("日");
 model->setHorizontalHeaderLabels(list_headlabels);

 Lan2CalDelegate* mdelegate=new Lan2CalDelegate(this);

 mview->setModel(model);
 mview->setItemDelegate(mdelegate);
 mview->verticalHeader()->hide();
 mview->setFixedSize(600,550);
 mview->viewport()->setAttribute(Qt::WA_Hover);

 //undisplay grid
// mview->setGridStyle(Qt::NoPen);//
 mview->setShowGrid(false);


 //set col width
 for(int i=0;i<7;++i){
     mview->setColumnWidth(i,50);


 }

 //set row height
 for(int i=0;i<6;++i){
     mview->setRowHeight(i,50);


 }

 int i=1;
 //set data
 for(int r=0;r<6;r++){
     for(int c=0;c<7;c++){
         model->setItem(r,c,new QStandardItem(QString("%1").arg(i++)));

     }
 }

mview->selectionModel()->select(model->index(0,0),QItemSelectionModel::Clear);

mview->setSelectionMode(QAbstractItemView::SingleSelection);
mview->selectionModel()->select(model->index(2,4),QItemSelectionModel::ClearAndSelect);



}

void Lan2CalCalendar::slot_leftarrowClick()
{
    qDebug()<<"click";
}

void Lan2CalCalendar::slot_rightarrowClick()
{

}

LAN2END
